﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ComLib.ComFun;
using System.Xml.Serialization;
using ComLib.ConfigService;

namespace KAImage.Config
{
    /// <summary>
    /// 高斯模糊和USM锐化参数选项
    /// </summary>
    [Serializable]
    [XmlRootAttribute("BlurSharpenOption", Namespace = "KAImage.Config", IsNullable = false)]
    public class BlurSharpenOption : XmlSerializeBase
    {
          /// <summary>
        /// 高斯模糊半径
        /// </summary>
        private int _gaussianRadius = 0;
        public int GaussianRadius
        {
            get
            {
                return _gaussianRadius;
            }
            set
            {
                _gaussianRadius = value;
            }
        }

        /// <summary>
        /// USM锐化程度值
        /// </summary>
        private int _usmDegree = 0;
        public int USMDegree
        {
            get
            {
                return _usmDegree;
            }
            set
            {
                _usmDegree = value;
            }
        }

        /// <summary>
        /// USM锐化半径
        /// </summary>
        private int _usmRadius = 0;
        public int USMRadius
        {
            get
            {
                return _usmRadius;
            }
            set
            {
                _usmRadius = value;
            }
        }
       
        public override bool Serialize()
        {
            return Serializer.SaveToXml(ConfigFilePath, this);
        }

        public override bool Load()
        {
            BlurSharpenOption obj = (BlurSharpenOption)Serializer.LoadFromXml(ConfigFilePath, this.GetType());
            if (obj != null)
            {
                this._gaussianRadius = obj._gaussianRadius;
                this._usmDegree = obj._usmDegree;
                this._usmRadius = obj._usmRadius;               
                this._nVer = obj._nVer;
                return true;
            }
            else
            {
                ErrorMessage = Serializer.Message;
                return false;
            }
        }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder("高斯模糊和USM锐化选项: ");
            FillFieldValueStringDelegate FillString =
               (string field, object val) =>
               {
                   if (val != null)
                   {
                       builder.Append("[");
                       builder.Append(field);
                       builder.Append("]: ");
                       builder.Append(val.ToString() + "; ");
                   }
               };
            FillString("[高斯模糊半径]:", _gaussianRadius);
            FillString("[USM锐化半径]:", _usmRadius);
            FillString("[USM锐化程度]:", _usmDegree);
            return builder.ToString();
        }
    }
}
